﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CRFSharp
{
    public class Node
    {
        public int x;
        public int y;
        public double alpha;
        public double beta;
        public int cost;
        public int bestCost;
        public Node prev;

        public List<int> fvector;

        public List<Path> lpath;
        public List<Path> rpath;

        public void clear()
        {
            x = y = 0;
            alpha = beta = 0.0;
            cost = 0;
            prev = null;
            fvector = null;

            lpath.Clear();
            rpath.Clear();
        }

        public Node()
        {
            x = 0;
            y = 0;
            alpha = 0.0;
            beta = 0.0;
            cost = 0;
            bestCost = 0;
            prev = null;

            lpath = new List<Path>();
            rpath = new List<Path>();

            fvector = null;
       
        }

        public void calcAlpha()
        {
            alpha = 0.0;

            for (int i = 0; i < lpath.Count; i++)
            {
                alpha = Utils.logsumexp(alpha, lpath[i].cost + lpath[i].lnode.alpha, (i == 0));
            }
            alpha += cost;
        }

        public void calcBeta()
        {
            beta = 0.0;

            for (int i = 0; i < rpath.Count; i++)
            {
                beta = Utils.logsumexp(beta, rpath[i].cost + rpath[i].rnode.beta, (i == 0));
            }
            beta += cost;
        }
    };
}
